var Workport = Workport || {};
// @Path("/Alert")
Workport.AlertAPI = (function(){

	var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Alert/';
	
	var urls = ["", "Reset", "AlertCount" ];
	
	function getUrl(/*index, replace1, replace2, ...*/) {
		var index, i, loops, r;
		loops = arguments.length;
		if (loops > 0) {
			index = arguments[0];
			r = root + urls[index];
			for (i = 1; i < loops; i++)
				r = r.replace("{"+i+"}", arguments[i]);
		}
		return r;
	}
	
	return {
		// @GET  @Path("/")
		// public AlertResponse GetUserAlertNotification()
		getAlert:function(handler,request){
			var domain = {};
			domain.ps = request.pageSize;
			if(request.offset){
				domain.offset = request.offset;
			}
			return sfw.Http.get(getUrl(0),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(toViewModel(data));
					}
				}
			},domain);
			function toViewModel(data){
				return data;
			}
		},
		// @PUT	@Path("/Reset")
		// public BasicResponse DeleteAlertNotificationHistory()
		resetAlert:function(handler){
			return sfw.Http.put(getUrl(1),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(toViewModel(data));
					}
				}
			});
			function toViewModel(data){
				return data;
			}
		},
		// @DELETE	@Path("/Reset")
		// public BasicResponse DeleteAlertNotificationHistory()
		deleteAlert:function(handler){
			return sfw.Http.del(getUrl(1),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(toViewModel(data));
					}
				}
			});
			function toViewModel(data){
				return data;
			}
		},
		// @GET	@Path("/AlertCount")
		// public AlertCountResponse GetUserAlertNotificationCount()
		countAlert:function(handler){
			return sfw.Http.get(getUrl(2),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(toViewModel(data));
					}
				}
			});
			function toViewModel(data){
				return data;
			}
		}
	}
})();
